/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package model;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.io.*;

/**
 *
 * @author acer
 */
public class RegisterModel {
    Connection connection;

    public RegisterModel(Connection connection) {
        this.connection = connection;
    }

    public void insertRegistration(String post_user,
                              String post_pass,
                              String post_confirm_pass,
                              String post_email,
                              String post_full_name,
                              String post_birthday,
                              String post_gender,
                              String post_about, String new_filename) throws SQLException
    {
        String query = "INSERT INTO user (username, password, email, gender, full_name, birth, avatar, about_me, post_count,comment_count) VALUES ('"
                + post_user
                + "',MD5('"+post_pass+"'),'"
                + post_email
                + "','"+post_gender
                + "','"+post_full_name
                + "','"+post_birthday
                + "','"+new_filename
                + "','"+post_about
                + "',0,0)";

        Statement statement = connection.createStatement();
        int val = statement.executeUpdate(query);
    }

    private void writeBytes(InputStream is,FileOutputStream os) throws IOException
    {
        // write bytes taken from uploaded file to target file
            int ch = is.read();
            while (ch != -1) {
                 os.write(ch);
                 ch = is.read();
            }
            os.close();
    }

}
